/*
 * Copyright user2010
 * All rights reserved
 */

package org.myorg.applitest.gui.main;

import org.myorg.applitest.gui.swing.components.frame.FrmNewItmRegUsrScr;
import org.myorg.applitest.gui.swing.components.frame.FrmNewItmAnm;
import org.myorg.applitest.gui.swing.components.frame.FrmNewItmRegUsrPrt;
import org.myorg.applitest.gui.swing.components.frame.FrmNewItmClt;
import org.myorg.applitest.gui.swing.components.panel.LbzHrzTextField;
import org.myorg.applitest.jdbc.connection.ConCreateDB;
import org.myorg.applitest.jdbc.connection.ConDropDB;
import org.myorg.applitest.loggin.PropsDbLogin;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author user
 */
public class FrmAppliTest extends JFrame implements ActionListener, WindowListener{

    public FrmAppliTest()
    {
        initComponents();
        
    }

        private void initComponents() {



        this.setTitle("appliTest");
        this.setSize(500, 300);
        jPanel1 = new javax.swing.JPanel();
        btnScr = new javax.swing.JButton();
        btnPrt = new javax.swing.JButton();
        btnAnm = new javax.swing.JButton();
        btnClt = new javax.swing.JButton();
        btnInstall = new javax.swing.JButton();
        btnUninstall = new javax.swing.JButton();
        this.txfPassword = new LbzHrzTextField("Pass: ", 10);


        btnScr.addActionListener(this);
        btnPrt.addActionListener(this);
        btnAnm.addActionListener(this);
        btnClt.addActionListener(this);
        btnInstall.addActionListener(this);
        btnUninstall.addActionListener(this);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 125, Short.MAX_VALUE)
        );

        btnScr.setText("New scr");
        btnPrt.setText("New prt");
        btnAnm.setText("New anm");
        btnClt.setText("New clt");
        this.btnInstall.setText("Install DB");
        this.btnUninstall.setText("Drop DB");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txfPassword)
                    .addComponent(btnClt)
                    .addComponent(btnScr)
                    .addComponent(btnPrt)
                    .addComponent(btnAnm)
                    .addComponent(btnInstall)
                    .addComponent(btnUninstall))

                .addGap(200, 200, 200)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(126, 126, 126))
            .addGroup(layout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addComponent(txfPassword)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnScr)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnPrt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAnm)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnClt)
                .addGap(30, 30, 30)
                .addComponent(btnInstall)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnUninstall)
                .addContainerGap(67, Short.MAX_VALUE))
        );

        pack();
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new FrmAppliTest().setVisible(true);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    Logger.getLogger(FrmNewItmRegUsrScr.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    public void actionPerformed (ActionEvent e)
    {
        try {
        PropsDbLogin.getSingletonObject().setCurrentuserLoginPassword("root", txfPassword.getText());
        if (e.getSource().equals((Object)btnScr))
        {
                JFrame frm = new FrmNewItmRegUsrScr();
        }
        else if (e.getSource().equals((Object)btnPrt))
        {
            JFrame frm = new FrmNewItmRegUsrPrt();
        }
        else if (e.getSource().equals((Object)btnClt))
        {
            JFrame frm = new FrmNewItmClt();
        }
        else if (e.getSource().equals((Object)btnAnm))
        {
            JFrame frm = new FrmNewItmAnm();
        }
        else if (e.getSource().equals((Object)btnInstall))
        {
            ConCreateDB con = new ConCreateDB();
            con.doJob(
                PropsDbLogin.getSingletonObject().getCurrentUserLogin(),
                PropsDbLogin.getSingletonObject().getCurrentUserPassword()
            );
        }
        else if (e.getSource().equals((Object)btnUninstall))
        {
            ConDropDB con = new ConDropDB();
            con.doJob(
                PropsDbLogin.getSingletonObject().getCurrentUserLogin(),
                PropsDbLogin.getSingletonObject().getCurrentUserPassword()
            );
        }
        } catch (Exception ex) {
                Logger.getLogger(FrmAppliTest.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

    JButton btnScr;
    JButton btnPrt;
    JButton btnAnm;
    JButton btnClt;
    JButton btnInstall;
    JButton btnUninstall;
    LbzHrzTextField txfPassword;

    private JPanel jPanel1;

    public void windowOpened(WindowEvent e) {

    }

    public void windowClosing(WindowEvent e) {

    }

    public void windowClosed(WindowEvent e) {
        this.dispose();
    }

    public void windowIconified(WindowEvent e) {

    }

    public void windowDeiconified(WindowEvent e) {

    }

    public void windowActivated(WindowEvent e) {

    }

    public void windowDeactivated(WindowEvent e) {

    }
}



